<?php

namespace App\Http\Controllers\Home;


use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Model\Goods;
use App\Model\Category;

class IndexController extends CommonController
{
    public function index()
    {
        //新品
        $newsGoods = Goods::orderBy('updated_at', 'desc')->limit(3)->get();
        //生日礼物
        //查找所有子元素
        $giftpid = 13;
        $giftids = Category::where('pid', $giftpid)->get();
        $giftidarr = [];
        foreach ($giftids as $giftid) {
            $giftidarr [] = $giftid['id'];
        }
        $giftDatas = Goods::whereIn('categories_id', $giftidarr)->orderBy('updated_at', 'desc')->limit(8)->get();
        return view('home.index.index', compact('newsGoods', 'giftDatas'));
    }

}
